﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;

namespace One.Test.MVC.FilterCenter
{
    public class FilterCenters : IAuthorizationFilter
    {
        /// <summary>
        ///  实现授权过滤器
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            // 获取Controller的名字
            string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            // 获取action的名字
            string actionName = filterContext.ActionDescriptor.ActionName;

            if (controllerName.ToLower() == "login")
            {
                // 进入登录页面不做任何处理，提交登录信息也不做任何处理
            }
            else
            {
                if (System.Web.HttpContext.Current.Session["loginUser"] == null)
                {
                    filterContext.Result = new RedirectResult("/Login/Login");
                }
            }
        }
    }
}